import { deepClone } from "@/utils/deepClone";
import handler from "./index";
let reducer = (
  state = {
    ...handler.state,
  },
  action: { type: string; value?: any }
) => {
  let newState = deepClone(state);
  for (const key in handler.actionsNames) {
    if (Object.prototype.hasOwnProperty.call(handler.actionsNames, key)) {
      // @ts-ignore
      const element = handler.actionsNames[key];
      if (action.type === element) {
        // @ts-ignore
        handler.actions[handler.actionsNames[key]](newState, action);
        break;
      }
    }
  }
  return newState;
};
export default reducer;
